home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 5 / Amiga Tools 5.iso / tools / developer-tools / c-tools / c_examples / picturedt / button.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-03-16  |  2.7 KB  |  110 lines

  1. //////////////////////////////////////////////////////////////////////////////
  2. // button.cpp
  3. //
  4. // Jeffry A Worth
  5. // November 10, 1995
  6. //////////////////////////////////////////////////////////////////////////////
  7.  
  8. //////////////////////////////////////////////////////////////////////////////
  9. // INCLUDES
  10. #include "aframe:include/button.hpp"
  11.  
  12. //////////////////////////////////////////////////////////////////////////////
  13. //
  14.  
  15. AFButton::AFButton()
  16. {
  17.   m_text="";
  18. }
  19.  
  20. AFButton::~AFButton()
  21. {
  22.   DestroyObject();
  23. }
  24.  
  25. void AFButton::DestroyObject()
  26. {
  27.   AFGadget::DestroyObject();
  28. }
  29.  
  30. void
  31. AFButton::FillGadgetStruct(LPExtGadget psgadget)
  32. {
  33.   AFRastPort rp(m_pwindow);
  34.   TEXTEXTENT te;
  35.   WORD w,h;
  36.  
  37.     AFGadget::FillGadgetStruct(psgadget);
  38.     
  39.     // Fill in coordinates to draw border
  40.     w=m_rect.Width()-1;
  41.     h=m_rect.Height()-1;
  42.     m_xyshine[0]=m_xyshine[2]=m_xyshine[3]=m_xyshine[5]=0;
  43.     m_xyshine[1]=h;
  44.     m_xyshine[4]=w;
  45.  
  46.     m_xyshadow[0]=1;
  47.     m_xyshadow[1]=m_xyshadow[3]=h;
  48.     m_xyshadow[2]=m_xyshadow[4]=w;
  49.     m_xyshadow[5]=0;
  50.  
  51.     // Fill in Border Structure
  52.     m_gborder.LeftEdge = m_gborder2.LeftEdge = 0;
  53.     m_gborder.TopEdge = m_gborder2.TopEdge = 0;
  54.     m_gborder.FrontPen = 2;
  55.     m_gborder2.FrontPen = 1;
  56.     m_gborder.BackPen = m_gborder2.BackPen = 0;
  57.     m_gborder.DrawMode = m_gborder2.DrawMode = JAM1;
  58.     m_gborder.Count = m_gborder2.Count = 3;
  59.     m_gborder.XY = m_xyshine;
  60.     m_gborder2.XY = m_xyshadow; 
  61.     m_gborder.NextBorder = &m_gborder2;
  62.     m_gborder2.NextBorder = NULL;
  63.  
  64.     m_sborder.LeftEdge = m_sborder2.LeftEdge = 0;
  65.     m_sborder.TopEdge = m_sborder2.TopEdge = 0;
  66.     m_sborder.FrontPen = 1;
  67.     m_sborder2.FrontPen = 2;
  68.     m_sborder.BackPen = m_sborder2.BackPen = 0;
  69.     m_sborder.DrawMode = m_sborder2.DrawMode = JAM1;
  70.     m_sborder.Count = m_sborder2.Count = 3;
  71.     m_sborder.XY = m_xyshine;
  72.     m_sborder2.XY = m_xyshadow; 
  73.     m_sborder.NextBorder = &m_sborder2;
  74.     m_sborder2.NextBorder = NULL;
  75.  
  76.     // Fill IntuiText Structure
  77.     rp.TextExtent(m_text.data(),m_text.length(),&te);
  78.     m_IntuiText.FrontPen = 1;
  79.     m_IntuiText.DrawMode = JAM1;
  80.     m_IntuiText.LeftEdge = ( m_rect.Width() - te.te_Width )/2;
  81.     m_IntuiText.TopEdge = ( m_rect.Height() - te.te_Height )/2 ;
  82.     m_IntuiText.ITextFont = &m_pwindow->m_textattr;
  83.     m_IntuiText.IText = (UBYTE*)m_text.data();
  84.     m_IntuiText.NextText = NULL;
  85.  
  86.     // Attach IntuiText Struct and Border Struct to gadget Struct
  87.     m_pgadget->GadgetText = &m_IntuiText;
  88.     m_pgadget->GadgetRender = &m_gborder;
  89.     m_pgadget->SelectRender = &m_sborder;
  90.     m_pgadget->Flags = GFLG_GADGHIMAGE | GFLG_EXTENDED;
  91. }
  92.  
  93. void AFButton::Create(char *text, AFWindow* pwindow, AFRect *rect, ULONG id)
  94. {
  95.   // Create string for the text
  96.   m_rect=*rect;
  97.   m_text=text;
  98.  
  99.   // Create the gadget
  100.   AFGadget::Create(pwindow,rect,id);
  101. }
  102.  
  103. void
  104. AFButton::SetText(char* text)
  105. {
  106.     m_text = text;
  107.  
  108.     // refresh gadget
  109. }
  110.